package cn.tedu.springmvc.config;

import cn.tedu.springmvc.interceptor.LoginInterceptoy;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@EnableWebMvc//增强模式,不开会406
@Configuration//此注解不是必须的
@ComponentScan("cn.tedu.springmvc")//必须配置当前配置类,不可配置在Spring的配置类中
//Spring MVC 配置类必须实现WebMvcConfigurer接口
public class SpringMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String> pathPatterns = new ArrayList<>();
        pathPatterns.add("/user/reg.do");
        pathPatterns.add("/user/login.do");
        registry.addInterceptor(new LoginInterceptoy())
                // .addPathPatterns(pathPatterns);
                .addPathPatterns("/**")
                //exclude排除
                .excludePathPatterns("/user/reg.do", "/user/login.do");
    }
}
